package ar.edu.unicen.pladema.vc1.formats.sur;

public class VertexReader implements IReader {
	private static final int INIT=0;
	private static final int VERTEX_NAME=1;
	private static final int VERTEX_X=2;
	private static final int VERTEX_Y=3;
	private static final int VERTEX_Z=4;
	private int state;
	private String lastVertex;
	
	public VertexReader() {
		state = INIT;
	}
	@Override
	public IReader readed(String token, Data3D data3d) {
		IReader response = DefaultReader.readers(token, this);
		if (response != null) {return response;}

		switch (state) {
			case INIT: {
				System.out.println("Cantidad de vertices:" + token);
				state = VERTEX_NAME;
				break;
			}
			case VERTEX_NAME: {
				data3d.newVertex(token);
				lastVertex = token;
				state = VERTEX_X;
				break;
			}
			case VERTEX_X: {
				data3d.setVertexX(lastVertex, token);
				state = VERTEX_Y;
				break;
			}
			case VERTEX_Y: {
				data3d.setVertexY(lastVertex, token);
				state = VERTEX_Z;
				break;
			}
			case VERTEX_Z: {
				data3d.setVertexZ(lastVertex, token);
				state = VERTEX_NAME;
				break;
			}
			default: {
				break;
			}
		}
		return this;
	}

}
